package evs.brp;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.net.SocketException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Marshaller {
	
	protected static Log log = LogFactory.getLog(Marshaller.class);
	
	public static void marshall(ObjectOutput objectOutput, Message message) {	
		log.info("marshalling: ");			

		log.info(message.toString());

		try {			
			objectOutput.writeObject(message);						
		}
		catch (SocketException se) {
			log.error(se);
			se.printStackTrace();
		}
		catch (IOException ioe) {
			log.error(ioe);
			ioe.printStackTrace();
		}	
		
		log.info("marshalling complete");	
	}
	
	public static Message demarshall(ObjectInput objectInput) {
		log.info("demarshalling:");

		Message message = new Message();
		
		try {
			message = (Message) objectInput.readObject();	

			log.info(message.toString());		
		}
		catch (IOException ioe) {
			log.error(ioe);
		}
		catch (ClassNotFoundException ioe) {
			log.error(ioe);
		}	
		
		log.info("demarshalling complete");
		
		return message;
	}

}
